//! @Author: DengLibin
//! @Date: Create in 2024-07-17 17:58:54
//! @Description:
//!

use axum::{Json, Router};
use chrono::Local;
use serde_json::{json, Value};

pub async fn route(router: Router) -> Router {
    let router = router.route("/now", axum::routing::get(now_utc));
    let router = router.route("/timestamp", axum::routing::get(now_utc_timestamp));
    router
}

/// @Author: DengLibin
/// @Date: Create in 2024-07-17 18:04:06
/// @Description: 获取当前时间
/// @return: Json<Value>
pub async fn now_utc() -> Json<Value> {
    //utc时间 0时区
    let time = my_util_lib::date::get_date_time_utc_now();

    //北京时间
    let now = Local::now().naive_local();
    //转成utc时间 时间不变
    let time2 = now.and_utc(); //北京时间
    let time3 = time2.to_utc(); //北京时间

    let time4 = time3.naive_utc().and_utc();
    let time5 = time3.naive_local().and_utc();

    Json(json!(vec![time, time2, time3, time4, time5]))
}

pub async fn now_utc_timestamp() -> Json<Value> {
    let time1 = my_util_lib::date::get_sys_timestamp_millis();
    let time2 = my_util_lib::date::get_chrono_timestamp_millis();
    let time3 = my_util_lib::date::get_utc_timestamp();
    let time4 = my_util_lib::date::get_local_date_time_utc_timestamp();
    Json(json!(format!("{}, {},{},{}", time1, time2, time3, time4)))
}
